package org.pearl.mybatis.demo.handler;

import org.apache.ibatis.reflection.factory.DefaultObjectFactory;

import java.util.List;
import java.util.Properties;

/**
 * Created by TD on 2021/6/9
 */
public class ExampleObjectFactory extends DefaultObjectFactory {

    // 处理默认构造方法
    @Override
    public <T> T create(Class<T> type) {
        return super.create(type);
    }

    // 处理有参构造方法
    @Override
    public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
        return super.create(type, constructorArgTypes, constructorArgs);
    }

    // 判断集合类型参数
    @Override
    public <T> boolean isCollection(Class<T> type) {
        return super.isCollection(type);
    }

    /**
     * mybatis核心配置文件中自配置<objectFactory><property></property></objectFactory>
     * 中的property标签的内容，会在加载配置文件后，设置到Properties对象中
     */
    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        System.out.println(properties.getProperty("userName"));
    }
}
